<?php
include '../classes/Authentication.php';
include '../classes/HTML.php';
session_start ();
$auth = new Authentication ();
$auth->checkAuthentication ($_SERVER['PHP_SELF'], 1);
HTML::createHeader('Benutzer erstellen', 'users_create.css');
$db = new DB_For_User();
?>
<body>
	<?php HTML::createLogobar($auth->getUser());?>
	<div class="container">
		<div class="row">
			<div class="col-md-3">
				<h3>Infos</h3>
				<p>Zur&uuml;ck zur &Uuml;bersicht:</p>
				<form method="post" action="tickets.php">
					<button type="submit" name="back" class="btn btn-default">Zur&uuml;ck &raquo;</button>
				</form>
			</div>
			<div class="col-md-4">
				<h2>Ticket</h2>
				<?php 
					if(isset($_POST['submit'])) {
							if($db->createTicket($_POST['titel'], $_POST['description'], $_POST['category'], $_POST['priority'], $_SESSION['user_ID']))
								header('Location: tickets.php');
							else 
								echo '<p style="color: red;">Fehler beim Erstellen, bitte Versuchen Sie es erneut</p>';
					}
				?>
				<form method="post" action="tickets_create.php">
					<div class="form-group">
						Titel <input type="text" name="titel" placeholder="Titel" class="form-control" value="<?php if(isset($_POST['titel'])) echo $_POST['titel'] ?>" required />
						Beschreibung <textarea rows="4" name="description" placeholder="Schreiben Sie hier eine Kurze Beschreibung" class="form-control" value="" required><?php if(isset($_POST['description'])) echo $_POST['description'] ?></textarea>
						Kategorie</br>
						<select name="category">
							<?php
								$categories = $db->getAllCategories();
								foreach($categories as $category) {
									if(isset($_POST['category']) && $_POST['category'] == $category['id']) {
										echo '<option selected="selected" value="' . $category['id'] . '">' . $category['description'] . '</option>';
									} else
										echo '<option value="' . $category['id'] . '">' . $category['description'] . '</option>';
								}
							?>
						</select></br>
						Priorit&auml;t</br>
						<select name="priority">
							<?php
								$priorities = $db->getAllPriorities();
								foreach($priorities as $priority) {
									if(isset($_POST['priority']) && $_POST['priority'] == $priority['id']) {
										echo '<option selected="selected" value="' . $priority['id'] . '">' . $priority['description'] . '</option>';
									} else
										echo '<option value="' . $priority['id'] . '">' . $priority['description'] . '</option>';
								}
							?>
						</select>
					</div>
					<button type="submit" name="submit" class="btn btn-default">Erstellen &raquo;</button>
				</form>
			</div>
		</div>
		<?php HTML::createFooter();?>
	</div>
	<?php HTML::includeJS();?>
</body>
</html>